#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
inline int read()
{
    int x=0,f=1;
    char tmp;
    tmp=getchar();
    if(tmp<'0'||tmp>'9')
    {
        if(tmp=='-')
            f=-1;
    }
    else
    {
        x=tmp-'0';
    }
    tmp=getchar();
    while(tmp>='0'&&tmp<='9')
    {
        x*=10;
        x+=tmp-'0';
        tmp=getchar();
    }
    return f*x;
}
int T,n,m,L,V,d[100005],v[100005],a[100005],p[100005],ans1,ans2,maxmonitord;
pair<int,int> judger[100];
bool specialA=1,specialB=1,detectedby[3005][3005];
vector<int>judgenum;
void solveA()
{
    int maxd=0,cedg=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]>V&&d[i]<=maxmonitord)
        {
            ans1++;
            maxd=max(maxd,d[i]);
        }
    }
    if(ans1==0) ans2=m;
    else ans2=m-1;
    //cout<<ans1<<endl<<ans2<<endl;
    //cout<<maxd<<" "<<cedg<<" "<<ans2<<endl;
    printf("%d %d\n",ans1,ans2);
    return;
}
void solveB()
{
    for(int i=0;i<n;i++)
    {
        if((((v[i]*v[i])+2*a[i]*(maxmonitord-d[i]))>(V*V))&&d[i]<=maxmonitord)
        {
            ans1++;
        }
    }
    if(ans1==0) ans2=m;
    else ans2=m-1;
    printf("%d %d\n",ans1,ans2);
    return;
}
void solve()
{
    //puts("solve");
    memset(detectedby,0,sizeof(detectedby));
    bool detected[105],used[105];
    memset(detected,0,sizeof(detected));
    memset(used,0,sizeof(used));
    //puts("init");
    for(int i=0;i<n;i++)
    {
        bool flag=0;
        for(int j=0;j<m;j++)
        {
            //cout<<i<<" "<<j<<endl;
            if((((v[i]*v[i])+2*a[i]*(p[j]-d[i]))>(V*V))&&d[i]<=p[j])
            {
                flag=1;
                judger[j].fir++;
                detectedby[i][j]=1;
                //cout<<i<<endl;
            }
        }
        if(flag)
        {
            ans1++;
            judgenum.pb(i);
        }
    }
    //puts("solveans1");
    //-------------------solve ans1------------------------
    int cedg=0;
    sort(judger,judger+m);
    //puts("sorted");
    for(int i=0;i<judgenum.size();i++)
    {
        for(int j=m-1;j>=0;j--)
        {
            //cout<<judgenum[i]<<" "<<j<<endl;
            if(detectedby[judgenum[i]][judger[j].sec])
            {
                if(used[judger[j].sec])
                {
                   //cout<<judgenum[i]<<" "<<j<<" "<<p[judger[j].sec]<<endl;
                   break;
                }
                else
                {
                    used[judger[j].sec]=1;
                    cedg++;
                    //cout<<judgenum[i]<<" "<<j<<" "<<p[judger[j].sec]<<endl;
                    break;
                }
            }
        }
    }
    ans2=m-cedg;
    printf("%d %d\n",ans1,ans2);
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T--)
    {
        n=read();
        m=read();
        L=read();
        V=read();
        specialA=1;
        specialB=1;
        maxmonitord=0;
        ans1=0;
        ans2=0;
        judgenum.clear();
        memset(judger,0,sizeof(judger));
        memset(d,0,sizeof(d));
        memset(v,0,sizeof(v));
        memset(a,0,sizeof(a));
        memset(p,0,sizeof(p));
        for(int i=0;i<n;i++)
        {
            d[i]=read();
            v[i]=read();
            a[i]=read();
            if(a[i]!=0) specialA=0;
            if(a[i]<=0) specialB=0;
        }
        for(int i=0;i<m;i++)
        {
            p[i]=read();
            judger[i].sec=i;
            maxmonitord=max(maxmonitord,p[i]);
        }
        if(specialA)
        {
            solveA();
            continue;
        }
        if(specialB)
        {
            solveB();
            continue;
        }
        solve();
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
